Skip to content

feat: implement event dispatching for incoming WhatsApp messages#230

Merged
gabrieljablonski merged 2 commits intomainfrom
gabriejablonski/feat-wa-cloud-provider-event-received
Feb 28, 2026
Merged

feat: implement event dispatching for incoming WhatsApp messages#230
gabrieljablonski merged 2 commits intomainfrom
gabriejablonski/feat-wa-cloud-provider-event-received

Conversation

@gabrieljablonski
Copy link
Member

@gabrieljablonski gabrieljablonski commented Feb 28, 2026

Pull Request Template

Description

Please include a summary of the change and issue(s) fixed. Also, mention relevant motivation, context, and any dependencies that this change requires.
Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

This change is Reviewable

Summary by CodeRabbit

  • New Features

    • WhatsApp incoming messages now dispatch provider events with comprehensive event information including event type and payload, enabling improved event tracking and monitoring capabilities.
  • Tests

    • Added extensive test coverage for WhatsApp provider event dispatching functionality, verifying correct event dispatch behavior and handling of edge cases including empty webhook payloads.

@gabrieljablonski gabrieljablonski self-assigned this Feb 28, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The WhatsApp incoming message service now dispatches provider events before processing messages. An event dispatcher is invoked with the event type, inbox, payload, and timestamp extracted from webhook parameters, enabling event tracking throughout the messaging pipeline.

Changes

Cohort / File(s) Summary
Event Dispatching Enhancement
app/services/whatsapp/incoming_message_whatsapp_cloud_service.rb
Added perform method that dispatches PROVIDER_EVENT_RECEIVED events with extracted event type, inbox, payload, and timestamp before calling the parent service. Includes whatsapp_cloud_event_type helper to extract event type from webhook params with fallback to 'unknown'.
Test Coverage
spec/services/whatsapp/incoming_message_whatsapp_cloud_service_spec.rb
New test context verifying event dispatch behavior, including assertions that dispatcher is called with correct parameters and no dispatch occurs when processed_params is blank.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

enhancement

Poem

🐰 A webhook hops into our service door,
Events dispatched like never before,
With timestamps and types, the story's told,
Provider events, a sight to behold!
The rabbit approves of tracking so true! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: implement event dispatching for incoming WhatsApp messages' directly and clearly describes the main implementation added in the changeset—event dispatching functionality for incoming WhatsApp messages in the IncomingMessageWhatsappCloudService.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gabriejablonski/feat-wa-cloud-provider-event-received

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gabrieljablonski
Copy link
Member Author

@CodeRabbit review

@codex review

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

@gabrieljablonski: I'll review the changes in this PR for you.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/services/whatsapp/incoming_message_whatsapp_cloud_service.rb (1)

18-20: Minor style inconsistency with key access.

This method uses symbol keys (:entry, :changes, :field) via dig, while processed_params (line 23) uses string keys ('changes', 'value') with try. Both work due to with_indifferent_access, but the mixed style could cause confusion. Consider aligning the key access style for consistency.

♻️ Optional: Align with symbol keys
 def whatsapp_cloud_event_type
-  params.dig(:entry, 0, :changes, 0, :field) || 'unknown'
+  params.dig(:entry, 0, :changes, 0, :field) || 'unknown'
 end

 def processed_params
-  `@processed_params` ||= params[:entry].try(:first).try(:[], 'changes').try(:first).try(:[], 'value')
+  `@processed_params` ||= params.dig(:entry, 0, :changes, 0, :value)
 end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/services/whatsapp/incoming_message_whatsapp_cloud_service.rb` around
lines 18 - 20, The method whatsapp_cloud_event_type mixes symbol-key access with
processed_params' string-key style; make the key access consistent by updating
processed_params (or other callers) to use symbol keys (e.g. use :entry,
:changes, :value) throughout, or alternatively change whatsapp_cloud_event_type
to use string keys to match processed_params—pick one consistent convention and
update references in whatsapp_cloud_event_type and processed_params so both use
the same key style (refer to methods whatsapp_cloud_event_type and
processed_params).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@spec/services/whatsapp/incoming_message_whatsapp_cloud_service_spec.rb`:
- Line 111: Remove the unused test variable by deleting the let(:dispatcher) {
instance_double(EventDispatcher) } declaration; the spec already stubs
Rails.configuration.dispatcher directly at the later block, so keep that stub
and remove the dead `dispatcher` symbol to avoid an unused variable in the spec.

---

Nitpick comments:
In `@app/services/whatsapp/incoming_message_whatsapp_cloud_service.rb`:
- Around line 18-20: The method whatsapp_cloud_event_type mixes symbol-key
access with processed_params' string-key style; make the key access consistent
by updating processed_params (or other callers) to use symbol keys (e.g. use
:entry, :changes, :value) throughout, or alternatively change
whatsapp_cloud_event_type to use string keys to match processed_params—pick one
consistent convention and update references in whatsapp_cloud_event_type and
processed_params so both use the same key style (refer to methods
whatsapp_cloud_event_type and processed_params).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56c5609 and 00fd0c2.

📒 Files selected for processing (2)
  • app/services/whatsapp/incoming_message_whatsapp_cloud_service.rb
  • spec/services/whatsapp/incoming_message_whatsapp_cloud_service_spec.rb

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@gabrieljablonski gabrieljablonski merged commit 88c2688 into main Feb 28, 2026
1 check passed
@gabrieljablonski gabrieljablonski deleted the gabriejablonski/feat-wa-cloud-provider-event-received branch February 28, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant